package coml.jiyun.hp.wanandroid.ui.fragment;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;

import coml.jiyun.hp.wanandroid.R;
import coml.jiyun.hp.wanandroid.base.BaseLazyFragment;
import coml.jiyun.hp.wanandroid.bean.SystemBean;
import coml.jiyun.hp.wanandroid.presenter.SystemPresenter;
import coml.jiyun.hp.wanandroid.ui.adapter.FlowSystemAdapter;
import coml.jiyun.hp.wanandroid.view.SystemView;
import qdx.stickyheaderdecoration.NormalDecoration;

/**
 * A simple {@link Fragment} subclass.
 */
public class SystemTwoFragment extends BaseLazyFragment<SystemPresenter>implements SystemView {


    private RecyclerView mRlv;
    private ArrayList<SystemBean.DataBean> dataBeans;
    private FlowSystemAdapter flowSystemAdapter;

    public SystemTwoFragment() {
        // Required empty public constructor
    }



    @Override
    protected void initListener() {

    }

    @Override
    protected void initData() {
        mPresenter.getSystem();
    }

    @Override
    protected SystemPresenter initPresenter() {
        return new SystemPresenter();
    }

    public void initView(View inflate) {
        mRlv = inflate.findViewById(R.id.system_two_Rlv);

        mRlv.setLayoutManager(new LinearLayoutManager(getContext()));
        dataBeans = new ArrayList<>();
        flowSystemAdapter = new FlowSystemAdapter(getContext(), dataBeans);
        mRlv.setAdapter(flowSystemAdapter);

        NormalDecoration decoration = new NormalDecoration() {
            @Override
            public String getHeaderName(int i) {
                return dataBeans.get(i).getName();
            }
        };
        mRlv.addItemDecoration(decoration);
    }

    @Override
    protected int getLayout() {
        return R.layout.fragment_system_two;
    }

    @Override
    public void setSystem(SystemBean system) {
        if (system != null && system.getData() != null && system.getData().size()>0){
            flowSystemAdapter.addData(system.getData());
        }
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }
}